<!--2019/5/23 22:27. by soft-->
<#assign title="安全设置">
<#include 'header.ftl'>

<div class="layui-card">
  <div class="layui-card-header">
    <div class="card-title">
      个人信息设置
    </div>
    <div class="header-tools">
    </div>
  </div>
  <div class="layui-card-body">

  </div>
</div>

<script type="text/html" id="userInfoBox">
  <div class="layui-row">
    <div class="layui-col-xs4">
      <form class="layui-form">
        <input type="hidden" name="id" value="{{d.id}}">
        <div class="layui-form-item">
          <label class="layui-form-label">姓名</label>
          <div class="layui-input-block">
            <input name="name" value="{{d.name}}" placeholder="姓名" class="layui-input"
                   lay-verify="required" lay-verType="tips">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">电话</label>
          <div class="layui-input-block">
            <input name="tel" value="{{d.tel}}" placeholder="电话" class="layui-input" maxlength="11"
                   lay-verify="required|phone" lay-verType="tips">
          </div>
        </div>

        <div class="layui-form-item">
          <label class="layui-form-label">密码</label>
          <div class="layui-input-block">
            <input type="password" name="password" placeholder="密码" class="layui-input">
          </div>
        </div>

        <div class="layui-form-item">
          <label class="layui-form-label">重复密码</label>
          <div class="layui-input-block">
            <input type="password" name="password2" placeholder="重复密码" class="layui-input"
                   lay-verify="pwd2" lay-verType="tips">
          </div>
        </div>

        <div class="layui-form-item">
          <div class="layui-input-block text-right">
            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="change">保存</button>
          </div>
        </div>
      </form>
    </div>
  </div>
</script>

<script>
  var methods, layerIndex;
  layui.use(['layer', 'form', 'jquery', 'laytpl'], function () {
    var laytpl = layui.laytpl;
    var layer = layui.layer;
    var form = layui.form;
    var $ = layui.$;

    var $userInfoBox = $('#userInfoBox');

    form.verify({
      pwd2: function (value) {
        if (!isEmpty(value)) {
          var pwd = $('[name="password"]').val()
          if (pwd !== value) {
            return '两次密码不一致！'
          }
        }
      }
    });

    $.post('/info', function (data) {
      var u = data.payload;
      laytpl($userInfoBox.html()).render(u, function (html) {
        $('.layui-card-body').html(html);
      })
    });

    form.on('submit(change)', function (fo) {
      console.log(fo);
      $.post('/change', fo.field, function (data) {
        if (data.success) {
          location.reload();
        } else {
          layer.alert(data.msg + " ", {title: '错误提示', icon: 1});
        }
      })
      return false;
    })
  });
</script>

<#include 'footer.ftl'>